package com.example.barry.pdf.Net;


import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.ProgressBar;


import com.example.barry.pdf.PgSQL.Site;
import com.example.barry.pdf.PgSQL.postgresSQL;
import com.example.barry.pdf.PgSQL.postgresSQLimpl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;




/**
 * Created by barry on 17-1-9.
 */

public class GetProjectAsynTask extends AsyncTask<String,Integer,List<Map<String, Object>>> {

    private postgresSQL pSQL = new postgresSQLimpl();
    private List<Site> siteList = new ArrayList<Site>();
    private List<Map<String, Object>> projectmaps = new ArrayList<Map<String, Object>>();
    Handler mhandler;
    public  GetProjectAsynTask(Handler handler ){
        this.mhandler = handler;
    }


    protected  List<Map<String, Object>> doInBackground(String... params) {
        siteList = pSQL.queryProjectsOfPlant(params[0], params[1]);
        for (int i = 0; i < siteList.size(); i++) {
            Map<String, Object> projectmap = new HashMap<String, Object>();
            projectmap.put("siteName", siteList.get(i).getName());
            projectmap.put("siteCommunityId", siteList.get(i).getGroupid());
            projectmaps.add(projectmap);
        }
     // Log.i("projectmaps", "-----" + projectmaps);
        return projectmaps;
    }


    protected void onPostExecute(List<Map<String, Object>> result) {
        Log.i("result", "" + result);
        Message msg = new Message();
        msg.what = 0x123;
        msg.obj  = result;
        mhandler.sendMessage(msg);
    }
    protected void onPreExecute() {
    }
}
